package demo.activiti.quickstart;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;

public class Sample {

    public static void main(String[] args) {
        // 获取流程引擎
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        // 获取相关服务
        RepositoryService repositoryService = processEngine.getRepositoryService();
        RuntimeService runtimeService = processEngine.getRuntimeService();
        TaskService taskService = processEngine.getTaskService();

        // 部署流程文件
        repositoryService.createDeployment().addClasspathResource("bpmn/process1.bpmn").deploy();

        // 启动流程
        runtimeService.startProcessInstanceByKey("process1");

        // 查询第一个任务
        Task task1 = taskService.createTaskQuery().singleResult();
        System.out.println(task1.getName());

        // 完成第一个任务
        taskService.complete(task1.getId());

        // 查询第二个任务
        Task task2 = taskService.createTaskQuery().singleResult();
        System.out.println(task2.getName());

        // 完成第二个任务
        taskService.complete(task2.getId());
    }
}
